package com.pan.behavioral.command.user;

import com.pan.behavioral.command.order.MyCommand;
import com.pan.behavioral.command.utils.CreateBeanUtils;

import javax.swing.*;
import java.awt.event.ActionEvent;

public class MyInvokerFrame {

    private JFrame jFrame = new JFrame("Command Example");
    private JButton saveButton = new JButton();
    private JButton printButton = new JButton();
    private JButton printAndSignatureButton = new JButton();

    private CreateBeanUtils createBeanUtils = CreateBeanUtils.INSTANCE;

    private MyCommand saveScreen = createBeanUtils.getSaveScreen();
    private MyCommand printScreen = createBeanUtils.getPrintScreen();
    private MyCommand printAndSignatureScreen = createBeanUtils.getPrintAndSignatureScreen();
    public MyInvokerFrame(){
    }


    private class MyAction extends AbstractAction {
        private MyCommand screenShot;
        public MyAction(MyCommand screenShot){
            this.screenShot = screenShot;
        }
        @Override
        public void actionPerformed(ActionEvent e) {
            //invoke调用command命令
            this.screenShot.execute();
        }
    }

    public void show(){

        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setLayout(null);//setLayout和setBounds不能同时使用


        saveButton.addActionListener(new MyAction(saveScreen));
        saveButton.setText("截屏保存");
        saveButton.setBounds(30,20,120,20);


        printButton.addActionListener(new MyAction(printScreen));
        printButton.setText("截屏展示");
        printButton.setBounds(30,50,120,20);

        printAndSignatureButton.addActionListener(new MyAction(printAndSignatureScreen));
        printAndSignatureButton.setText("截屏和签名展示");
        printAndSignatureButton.setBounds(30,80,120,20);


        jFrame.add(printButton);
        jFrame.add(saveButton);
        jFrame.add(printAndSignatureButton);
        jFrame.setBounds(0,0,140,160);
//        jFrame.pack();
        jFrame.setVisible(true);
    }



}
